package com.softer.chengxin.report.controller;

import com.github.pagehelper.PageInfo;
import com.softer.chengxin.common.domin.Common;
import com.softer.chengxin.common.domin.Page;
import com.softer.chengxin.report.entity.Report;
import com.softer.chengxin.report.service.ReportPrintService;
import com.softer.chengxin.score.entity.ScoreCompositeProvince;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;

/**
 * 信用报告打印
 *
 * @author Gong Zhiyang
 * @date 2020/1/18
 */
@RestController
@RequestMapping("/api/report")
public class ReportPrintController {
    @Autowired
    private ReportPrintService reportService;

    /**
     * 查询信用报告列表
     *
     * @param scoreCompositeProvince 查询实体
     * @param page                   分页实体
     * @return 列表
     */
    @PostMapping("/getReportList")
    public PageInfo<ScoreCompositeProvince> getReportList(ScoreCompositeProvince scoreCompositeProvince, Page page, HttpSession session) {
        String loginName = (String) session.getAttribute(Common.LOGIN_NAME);
        if (StringUtils.isBlank(loginName)) {
            return new PageInfo();
        }
        return reportService.getReportList(scoreCompositeProvince, page, loginName);
    }

    /**
     * 查询信用报告
     *
     * @param id 信用ID
     * @return 信用报告
     */
    @PostMapping("/getReportById")
    public Report getReportById(Integer id, HttpSession session) {
        String loginName = (String) session.getAttribute(Common.LOGIN_NAME);
        if (StringUtils.isBlank(loginName)) {
            return new Report();
        }
        return reportService.getReportById(id);
    }

}
